package com.open.capacity.prints.controller;

import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.prints.entity.BillNhgmpzwts;
import com.open.capacity.prints.service.BillNhgmpzwtsService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * 农行购买凭证委托书
 *
 * @author
 * @email
 * @date 2022-01-11 09:59:08
 */
@RestController
@RequestMapping("nhgmpzwts")
@Api(tags = "农行购买凭证委托书")
public class BillNhgmpzwtsController {

    @Autowired
    private BillNhgmpzwtsService pbillNhgmpzwtsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('pbill_nhgmpzwts:pbillnhgmpzwts:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = pbillNhgmpzwtsService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询记录
     */
    @RequestMapping("/findByCustomerName")
    @PreAuthorize("hasAnyAuthority('pbill_nhgmpzwts:pbillnhgmpzwts:list')")
    public Result findByCustomerName(String customerName) {
        return Result.succeed(pbillNhgmpzwtsService.findByCustomerName(customerName));
    }

    /**
     * 查询记录
     */
    @RequestMapping("/findByJbrName")
    @PreAuthorize("hasAnyAuthority('pbill_nhgmpzwts:pbillnhgmpzwts:list')")
    public Result findByJbrName(String jbrName) {
        return Result.succeed(pbillNhgmpzwtsService.findByJbrName(jbrName));
    }


    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('pbill_nhgmpzwts:pbillnhgmpzwts:list')")
    public Result findById(String id) {
        return Result.succeed(pbillNhgmpzwtsService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('pbill_nhgmpzwts:pbillnhgmpzwts:save')")
    public Result save(@RequestBody @Valid BillNhgmpzwts pbillNhgmpzwts, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            keyValue = pbillNhgmpzwtsService.save(pbillNhgmpzwts);
        } else {
            pbillNhgmpzwts.setId(keyValue);
            keyValue = pbillNhgmpzwtsService.update(pbillNhgmpzwts);
        }
        return Result.succeed(keyValue, "保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('pbill_nhgmpzwts:pbillnhgmpzwts:delete')")
    public Result delete(@PathVariable String id) {
        pbillNhgmpzwtsService.delete(id);
        return Result.succeed("删除成功");
    }

}
